| Conditions | 13 |
| Paths | 9 |
| Total Lines | 137 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like onlinebanktransfer.js ➔ payoneSwitchOnlineBankTransfer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /** |
||
| 29 | function payoneSwitchOnlineBankTransfer(element, country, currency) |
||
| 30 | { |
||
| 31 | if (element == undefined) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | |||
| 35 | var ElementValue = element.value; |
||
| 36 | var ElementValueSplit = ElementValue.split('_'); |
||
| 37 | var typeId = ElementValueSplit[0]; |
||
| 38 | var typeCode = ElementValueSplit[1]; |
||
| 39 | |||
| 40 | $("payone_online_bank_transfer_obt_type").setValue(typeCode); |
||
| 41 | $("payone_online_bank_transfer_config_id").setValue(typeId); |
||
| 42 | |||
| 43 | var accountNumberWrap = $('account_number_wrap'); |
||
| 44 | var bankCodeWrap = $('bank_code_wrap'); |
||
| 45 | var sepaIbanWrap = $('sepa_iban_wrap'); |
||
| 46 | var sepaBicWrap = $('sepa_bic_wrap'); |
||
| 47 | var bankGroupWrapAt = $('bank_group_wrap_at'); |
||
| 48 | var bankGroupWrapNl = $('bank_group_wrap_nl'); |
||
| 49 | |||
| 50 | var accountNumberInput = $('payone_online_bank_transfer_account_number'); |
||
| 51 | var bankCodeInput = $('payone_online_bank_transfer_bank_code'); |
||
| 52 | var sepaIbanInput = $('payone_online_bank_transfer_sepa_iban'); |
||
| 53 | var sepaBicInput = $('payone_online_bank_transfer_sepa_bic'); |
||
| 54 | var bankGroupSelectAt = $('payone_online_bank_transfer_bank_group_at'); |
||
| 55 | var bankGroupSelectNl = $('payone_online_bank_transfer_bank_group_nl'); |
||
| 56 | var sofortueberweisungShowIban = $('payone_online_bank_transfer_pnt_show_iban'); |
||
| 57 | |||
| 58 | if (ElementValue == '' || typeCode == 'PFF' || typeCode == 'PFC' || typeCode == 'P24') { |
||
| 59 | disableAll(); |
||
| 60 | } else if (typeCode == 'PNT') { |
||
| 61 | disableAll(); |
||
| 62 | if (country == 'CH' && currency == 'CHF') { |
||
| 63 | enableAccountNumber(); |
||
| 64 | enableBankCode(); |
||
| 65 | } else { |
||
| 66 | if (sofortueberweisungShowIban.value == 1) { |
||
| 67 | enableSepaIban(); |
||
| 68 | enableSepaBic(); |
||
| 69 | } else { |
||
| 70 | disableAll(); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } else if (typeCode == 'GPY') { |
||
| 74 | disableAll(); |
||
| 75 | enableSepaIban(); |
||
| 76 | enableSepaBic(); |
||
| 77 | } else if (typeCode == 'EPS') { |
||
| 78 | disableAll(); |
||
| 79 | enableBankGroupAt(); |
||
| 80 | } else if (typeCode == 'IDL') { |
||
| 81 | disableAll(); |
||
| 82 | enableBankGroupNl(); |
||
| 83 | } |
||
| 84 | |||
| 85 | function disableAll() |
||
| 86 | { |
||
| 87 | if(accountNumberWrap) { |
||
| 88 | accountNumberWrap.hide(); |
||
| 89 | accountNumberInput.setAttribute("disabled", "disabled"); |
||
| 90 | } |
||
| 91 | |||
| 92 | if(bankCodeWrap) { |
||
| 93 | bankCodeWrap.hide(); |
||
| 94 | bankCodeInput.setAttribute("disabled", "disabled"); |
||
| 95 | } |
||
| 96 | |||
| 97 | if(sepaIbanWrap) { |
||
| 98 | sepaIbanWrap.hide(); |
||
| 99 | sepaIbanInput.setAttribute("disabled", "disabled"); |
||
| 100 | } |
||
| 101 | |||
| 102 | if(sepaBicWrap) { |
||
| 103 | sepaBicWrap.hide(); |
||
| 104 | sepaBicInput.setAttribute("disabled", "disabled"); |
||
| 105 | } |
||
| 106 | |||
| 107 | if(bankGroupWrapAt) { |
||
| 108 | bankGroupWrapAt.hide(); |
||
| 109 | bankGroupSelectAt.setAttribute("disabled", "disabled"); |
||
| 110 | } |
||
| 111 | |||
| 112 | if(bankGroupWrapNl) { |
||
| 113 | bankGroupWrapNl.hide(); |
||
| 114 | bankGroupSelectNl.setAttribute("disabled", "disabled"); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | function enableAccountNumber() |
||
| 119 | { |
||
| 120 | if(accountNumberWrap) { |
||
| 121 | accountNumberWrap.show(); |
||
| 122 | accountNumberInput.removeAttribute("disabled"); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | function enableBankCode() |
||
| 127 | { |
||
| 128 | if(bankCodeWrap) { |
||
| 129 | bankCodeWrap.show(); |
||
| 130 | bankCodeInput.removeAttribute("disabled"); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | function enableSepaIban() |
||
| 135 | { |
||
| 136 | if(sepaIbanWrap) { |
||
| 137 | sepaIbanWrap.show(); |
||
| 138 | sepaIbanInput.removeAttribute("disabled"); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | function enableSepaBic() |
||
| 143 | { |
||
| 144 | if(sepaBicWrap) { |
||
| 145 | sepaBicWrap.show(); |
||
| 146 | sepaBicInput.removeAttribute("disabled"); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | function enableBankGroupAt() |
||
| 151 | { |
||
| 152 | if(bankGroupWrapAt) { |
||
| 153 | bankGroupWrapAt.show(); |
||
| 154 | bankGroupSelectAt.removeAttribute("disabled"); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | function enableBankGroupNl() |
||
| 159 | { |
||
| 160 | if(bankGroupWrapNl) { |
||
| 161 | bankGroupWrapNl.show(); |
||
| 162 | bankGroupSelectNl.removeAttribute("disabled"); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 173 |